import request from '@/utils/request'
type T = {
  fileName: string | null
  pageNo: number
  pageSize: number
}
interface AddFormState {
  fileName: string | null
  fileType: string | null
  ossUrl: string | null
  downloadOrgId: string[]
}
const getFileList = (data: T) => {
  return request({
    url: '/fileManage/condition',
    method: 'POST',
    data,
  })
}
const addFile = (data: AddFormState) => {
  return request({
    url: '/fileManage/add',
    method: 'POST',
    data,
  })
}
type DelType = {
  id: string
  fileUrl: string
}
const delFile = (data: DelType) => {
  return request({
    url: '/fileManage/del',
    method: 'POST',
    data,
  })
}
const getFileInfos = (data: AddFormState) => {
  return request({
    url: '/fileManage/add',
    method: 'POST',
    data,
  })
}
const uploadFile = (data: any) => {
  return request({
    url: '/fileManage/upload',
    method: 'POST',
    data,
  })
}
const downloadFile = (params: { fileUrl: string }) => {
  return request({
    url: '/fileManage/download/',
    method: 'GET',
    params,
    responseType: 'arraybuffer',
  })
}
const fileApi = {
  getFileList,
  addFile,
  delFile,
  getFileInfos,
  uploadFile,
  downloadFile,
}
export default fileApi
